<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon-comment" class="icon32"><br/></div><h2>编辑评论</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">列表</a></li>
            <li><a href="#tabs-2">编辑</a></li>
        </ul>
        <div id="tabs-1">
            <table class="list-table">
                <thead class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="10%">昵称</th>
                        <th width="45%">评论内容</th>
                        <th width="15%">评论时间</th>
                        <th width="15%">IP地址</th>
                        <th width="10%">编辑</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($this->commentList)) : ?>
                        <?php foreach ($this->commentList as $comment) : ?>
                    <tr>
                        <td><?php echo $this->escape($comment->commentId) ?></td>
                        <td><?php echo $this->escape($comment->nickName) ?></td>
                        <td><?php echo $this->escape($comment->comment) ?></td>
                        <td><?php echo $this->escape($comment->replyTime) ?></td>
                        <td><?php echo $this->escape($comment->ip) ?></td>
                        <td>
                            <a href="javascript:void(0)" onclick="editComment(<?php echo $this->escape($comment->commentId) ?>)">编辑</a> |
                            <a href="javascript:if(confirm('确实要删除该条评论吗?'))location='/backend/del/comment/id/<?php echo $this->escape($comment->commentId) ?>'">删除</a>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
                <tfoot class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="10%">昵称</th>
                        <th width="45%">评论内容</th>
                        <th width="15%">评论时间</th>
                        <th width="15%">IP地址</th>
                        <th width="10%">编辑</th>
                    </tr>
                </tfoot>
            </table>
            <?php if($this->commentId == 0 && !empty($this->commentList)) echo $this->paginationControl($this->commentList,'Elastic','pagebar.phtml'); ?>
        </div>
        <div id="tabs-2" class="editor-area">
            <form action="/backend/edit/comment/" method="post" onsubmit="return submitForm();">
                <div class="titlebox">
                    <h3><span>昵称</span></h3>
                    <input type="text" class="title" id="nickname" name="nickname" autocomplete="off" tabindex="1" size="30" value="<?php echo $this->escape($this->commentInfo->nickname) ?>" disabled />
                </div>
                <div>
                    <h3><span>内容</span></h3>
                    <textarea id="comment" name="comment" cols="100" rows="4"><?php echo $this->escape($this->commentInfo->comment) ?></textarea>
                </div>
                <div id="message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="修改" name="publish"/>
                    <input id="commentId" name="commentId" type="hidden" value="<?php echo $this->escape($this->commentInfo->commentId) ?>" />
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
<?php if($this->commentId > 0): ?>
            disabled: [0],
<?php else: ?>
            disabled: [1],
<?php endif; ?>
            collapsible: true
        });
    });

    function submitForm(){
        if ($("#comment").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入评论内容!");
            return false;
        } else {
            return true;
        }
    }

    function editComment(id){
        $("#tabs").tabs('option', 'disable', []);
        window.location.href = '/backend/list/comment/id/'+ id + '#tabs-' + 2;
    }
</script>
<?php echo $this->render('footer.phtml'); ?>